package com.zhongkun.datahome.service.processor.dto;

import com.alibaba.excel.annotation.ExcelProperty;
import com.zhongkun.datahome.common.annotation.Excel;
import com.zhongkun.datahome.service.constant.SkuStatusEnum;
import com.zhongkun.datahome.service.req.cmd.sku.SkuCmd;
import com.zhongkun.datahome.service.req.qry.sku.SkuExistQry;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.List;

/**
 * 映射 Excel 数据的实体类
 */
@Data
public class StandardData {
    // 记录所在行号
    private int rowIndex;

    // 新增字段及注解
    @NotNull(message = "【所属空间】不能为空")
    @Length(min = 2, max = 32, message = "【所属空间】长度应该在{min}到{max}之间")
    @ExcelProperty(index = 0)
    @Excel(name = "所属空间")
    private String room;

    @NotNull(message = "【类目名称】不能为空")
    @Length(min = 2, max = 32, message = "【类目名称】长度应该在{min}到{max}之间")
    @ExcelProperty(index = 1)
    @Excel(name = "类目名称")
    private String categoryName;

    @NotNull(message = "【数量】不能为空")
    @Min(value = 0, message = "【数量】不能小于{value}")
    @Max(value = 999999999, message = "【数量】不能超过{value}")
    @ExcelProperty(index = 2)
    @Excel(name = "数量")
    private BigDecimal quantity;

    @NotNull(message = "【单位】不能为空")
    @Length(min = 1, max = 32, message = "【单位】长度应该在{min}到{max}之间")
    @ExcelProperty(index = 3)
    @Excel(name = "单位")
    private String unit;

    @NotNull(message = "【商品名称】不能为空")
    @Length(min = 2, max = 64, message = "【商品名称】长度应该在{min}到{max}之间")
    @ExcelProperty(index = 4)
    @Excel(name = "商品名称")
    private String skuName;

    @NotNull(message = "【品牌】不能为空")
    @Length(min = 1, max = 32, message = "【品牌】长度应该在{min}到{max}之间")
    @ExcelProperty(index = 5)
    @Excel(name = "品牌")
    private String brandName;

//    @ExcelProperty(index = 6)
//    @Excel(name = "图片", cellType = Excel.ColumnType.IMAGE)
//    private String skuPic;

    // @NotNull(message = "【型号】不能为空")
    @Length(min = 0, max = 128, message = "【型号】长度应该在{min}到{max}之间")
    @ExcelProperty(index = 7)
    @Excel(name = "型号")
    private String specification;

    @NotNull(message = "【渠道】不能为空")
    @Length(min = 2, max = 32, message = "【渠道】长度应该在{min}到{max}之间")
    @ExcelProperty(index = 8)
    @Excel(name = "渠道")
    private String channel;

    //@NotNull(message = "【客户姓名】不能为空")
    @Length(max = 512, message = "【备注】长度不能超过{max}")
    @ExcelProperty(index = 9)
    @Excel(name = "备注")
    private String remark;

    private List<String> urls;

    public String getKey() {
        return MessageFormat.format("{0}-{1}-{2}-{3}-{4}", this.getSkuName(), this.getCategoryName(), this.getUnit(), this.getBrandName(), this.getSpecification());
    }

    public SkuExistQry toSkuExistQry() {
        SkuExistQry skuExistQry = new SkuExistQry();
        skuExistQry.setBrandName(this.getBrandName());
        skuExistQry.setCategory(this.getCategoryName());
        skuExistQry.setSkuName(this.getSkuName());
        skuExistQry.setUnit(this.getUnit());
        skuExistQry.setSpecification(this.getSpecification());
        return skuExistQry;
    }

    public SkuCmd convertSku() {
        SkuCmd sku = new SkuCmd();
        sku.setBrandName(this.getBrandName());
        sku.setCategory(this.getCategoryName());
        sku.setSkuName(this.getSkuName());
        sku.setUnit(this.getUnit());
        sku.setSpecification(this.getSpecification());
        sku.setRemark(this.getRemark());
        sku.setStatus(SkuStatusEnum.ON_SHELF.getStatus());
        // sku.setPictureUrls(List.of(this.getSkuPic()));
        return sku;
    }
}